<?php
/**
 * 后台Index相关
 */
namespace Admin\Controller;
use Think\Controller;
use Think\Exception;

/**
 * 文章内容管理
 */
class AboutController extends CommonController {

    public function index() {
        if($_POST['id']){
            return $this->save($_POST);
        }
        $id=1;
        $about = D("About")->find($id);
        $model = CONTROLLER_NAME;
        $this->assign('model', $model);
        $this->assign('about',$about);
        $this->display();
    }

    public function contact(){
        if($_POST['id']){
            return $this->save($_POST);
        }
        $id=1;
        $contact = D("About")->find($id);
        $model = CONTROLLER_NAME;
        $this->assign('model', $model);
        $this->assign('contact',$contact);
        $this->display();
    }

    public function brand(){
        if ($_POST['id']) {
            return $this->save($_POST);
        }
        $id = 1;
        $brand = D("About")->find($id);
        $model = CONTROLLER_NAME;
        $this->assign('model', $model);
        $this->assign('brand', $brand);
        $this->display();
    }

    public function save($data){
        $id = $data['id'];
        unset($data['id']);
        try {
            $id = D("About")->updateById($id, $data);
            if($id === false) {
                return show(0,'更新失败');
            }
            return show(1,'更新成功');
        }catch(Exception $e) {
            return show(0,$e->getMessage());
        }
    }

}